Skip to content

Add tessera attribute#1986

Draft
jumerckx wants to merge 9 commits intomainfrom
tessera_defs
Draft

Add tessera attribute#1986
jumerckx wants to merge 9 commits intomainfrom
tessera_defs

Conversation

@jumerckx
Copy link
Collaborator

@trace tessera function reciprocal(x)
	return 1/x
end

This will add an attribute with name tessera_name and value a stringattr with the function name ("reciprocal") to the generated MLIR function. (note that you need @code_hlo optimize=false to see this attribute, otherwise it is inlined.)

@code_hlo optimize=false reciprocal.(x)

generates code containing:

  func.func private @"####reciprocalinternal#267#287"(%arg0: tensor<f64> {enzymexla.memory_effects = []}) -> (tensor<f64>, tensor<f64>) attributes {enzymexla.memory_effects = [], tessera_name = "reciprocal"} {
    %c = stablehlo.constant dense<1> : tensor<i64>
    %0 = stablehlo.convert %c : (tensor<i64>) -> tensor<f64>
    %1 = stablehlo.divide %0, %arg0 : tensor<f64>
    return %1, %arg0 : tensor<f64>, tensor<f64>
  }

(note the tessera_name attribute)


It might be nicer to have a dedicated macro, i.e.:

@tessera function reciprocal(x)
	1/x
end

I just did it this way because it was quicker to reuse some stuff.

```
@trace tessera mysin(x)=sin(x)
```
This will add an attribute with name `tessera_name` and value a
stringattr with the function name (`"mysin"`) to the generated function
for mysin. (note that you need `@code_hlo optimize=false` to see this
attribute, otherwise it is inlined.)
@jessicacotturone21
Copy link
Collaborator

jessicacotturone21 commented Jan 28, 2026

@tessera_op "reciprocal" function reciprocal(x)
	return 1/x
end

Now a custom @tessera_op macro can also be used with a string like "reciprocal" to add a tessera_op attribute to a function declaration.

end

# Get function name from expression
fname_expr = func_expr.args[1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
fname_expr = func_expr.args[1]


return quote
# Define the function and register tessera_op
$(esc(traced_expr))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
$(esc(traced_expr))

$(esc(fname_sym))
end
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change


function compile_call_expr(_mod, compiler, options::Dict, args...)
while length(args) > 1
option, args = args[1], args[2:end]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
option, args = args[1], args[2:end]

@noinline function call(
f, args...; location=mlir_stacktrace("call", @__FILE__, @__LINE__), tessera_op=nothing
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

include("serialization/Serialization.jl")

using .Compiler: @compile, @code_hlo, @code_mhlo, @jit, @code_xla, traced_getfield, compile
using .Compiler: @compile, @code_hlo, @code_mhlo, @jit, @code_xla, @tessera_op, traced_getfield, compile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
using .Compiler: @compile, @code_hlo, @code_mhlo, @jit, @code_xla, @tessera_op, traced_getfield, compile
using .Compiler:
@compile, @code_hlo, @code_mhlo, @jit, @code_xla, @tessera_op, traced_getfield, compile

return 1 ./ x
end


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

return sin.(sum(x) .+ x)
end


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change


hlo2 = repr(@code_hlo optimize = false foo(x))
@test occursin("tessera_op = \"foo\"", hlo2)
end No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
end
end

@jessicacotturone21 jessicacotturone21 changed the title Add tessera option to @trace Add tessera attribute Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants